package com.itheima.controller;

import com.itheima.pojo.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/jsonparam")
public class ParamJsonController {
    /**
     * @RequestBody 帮助我们接受json格式的数据并自动封装
     * @param list
     * @return
     */
    @RequestMapping("/json1")
    @ResponseBody
    public String json1(@RequestBody List<String> list){
        System.out.println(list);
        return "{'info':'hello'}";
    }

    @RequestMapping("/json2")
    @ResponseBody
    public String json2(@RequestBody Person person){
        System.out.println(person);
        return "{'info':'hello'}";
    }

    @RequestMapping("/json3")
    @ResponseBody
    public String json3(@RequestBody List<Person> list){
        System.out.println(list);
        return "{'info':'hello'}";
    }

    /**
     * 出不来
     * @return
     */
    @RequestMapping("/resp1")
    public String response1(){
        System.out.println("response1");
        return "/html/index.html";
    }

    @ResponseBody
    @RequestMapping("/resp2")
    public Person response2(){
        System.out.println("response2");
        Person person = new Person();
        person.setId(1);
        person.setName("张三");
        return person;
    }
}
